package com.rabbitMq.producer;

import org.springframework.amqp.core.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

@SpringBootApplication
public class RabbitMqProducerApplication {

    public static void main(String[] args) {
        SpringApplication.run(RabbitMqProducerApplication.class, args);
    }

    //========================================================== Direct Exchange
    //队列 起名：testDirectQueue
    @Bean
    public Queue testDirectQueue1() {
        return new Queue("TestDirectQueue1", true);  //true 是否持久
    }

    //队列 起名：testDirectQueue1
    @Bean
    public Queue testDirectQueue2() {
        return new Queue("TestDirectQueue2", true);  //true 是否持久
    }

    //Direct交换机 起名：TestDirectExchange
    @Bean
    DirectExchange testDirectExchange() {
        return new DirectExchange("TestDirectExchange");
    }

    //绑定  将队列和交换机绑定, 并设置用于匹配键：TestDirectRouting
    @Bean
    Binding bindingDirect() {
        return BindingBuilder.bind(testDirectQueue1()).to(testDirectExchange()).with("TestDirectRouting1");
    }

    //绑定  将队列和交换机绑定, 并设置用于匹配键：TestDirectRouting1
    @Bean
    Binding bindingDirect1() {
        return BindingBuilder.bind(testDirectQueue2()).to(testDirectExchange()).with("TestDirectRouting2");
    }


    //========================================================== Fanout Exchange
    @Bean
    FanoutExchange testFanoutExchange() {
        return new FanoutExchange("TestFanoutExchange");
    }

    @Bean
    Binding bindingFanout() {
        return BindingBuilder.bind(testDirectQueue1()).to(testFanoutExchange());
    }

    @Bean
    Binding bindingFanout1() {
        return BindingBuilder.bind(testDirectQueue2()).to(testFanoutExchange());
    }

    //========================================================== Topic Exchange
    @Bean
    TopicExchange testTopicExchange() {
        return new TopicExchange("TestTopicExchange");
    }

    @Bean
    Binding bindingTopic1() {
        return BindingBuilder.bind(testDirectQueue1()).to(testTopicExchange()).with("*.wlx.*");
    }

    @Bean
    Binding bindingTopic2() {
        return BindingBuilder.bind(testDirectQueue2()).to(testTopicExchange()).with("*.wlx.*");
    }

    @Bean
    Binding bindingTopic3() {
        return BindingBuilder.bind(testDirectQueue2()).to(testTopicExchange()).with("wlx.#");
    }
}
